/************************************************************************************/
/*  Program name CAPCFAIMP_ASSET_KEYWORDS.sql                                        	*/
/*  Creater:  CHAN BILLY (PCCW - UniHub)                                         	*/
/*************   History   *************************                                */
/* 29 MAY, 2006   CHAN BILLY         First created                               	*/
/************************************************************************************/
SET SERVEROUTPUT ON SIZE 1000000;



DECLARE
	lv_Prog_ID		VARCHAR2(100)	:=	'CAPCFAIMP_ASSET_KEYWORDS';

	lv_Scc_Count	NUMBER	:=	0;
	lv_Err_Count	NUMBER	:=	0;
	lv_Err_Msg		VARCHAR2(500)	:=	'No Error';

	CURSOR Cur_F IS
	SELECT
		*
	FROM
		CRST_CFA_ASSET_KEYWORDS;
	
	lv_Seq_ID NUMBER;
	

BEGIN
	FOR C1 IN Cur_F LOOP
		BEGIN		
			
			INSERT INTO CFA_ASSET_KEYWORDS
			VALUES
			(
			CAPBRIMP_MAPPING.GetAssetKeyMapping(C1.CODE_COMBINATION_ID),
			CAPBRIMP_MAPPING.GetOrgMapping(C1.S_ORG_ID),
			CAPBRIMP_MAPPING.GetBGMapping(C1.S_BUSINESS_GROUP_ID) 
			);
		EXCEPTION
			WHEN OTHERS THEN
				DBMS_OUTPUT.Put_Line(SQLERRM);
				lv_Err_Count	:=	lv_Err_Count + 1;
		END;
		lv_Scc_Count	:=	lv_Scc_Count	+	1;
	END LOOP;
	
	IF	lv_Err_Count	>	0	THEN
		ROLLBACK;
	END IF;

	INSERT INTO CAPCNV_LOG(
		PROG_ID,
		PROCESS_DATE,
		RECORD_PROCESSED,
		RECORD_REJECTED,
		RECORD_EXTRACTED,
		ERR_MSG
	) VALUES (
		lv_Prog_ID,
		SYSDATE,
		lv_Scc_Count,
		lv_Err_Count,
		lv_Scc_Count-lv_Err_Count,
		lv_Err_Msg
	);
	
	COMMIT;
END;
/

